package cn.cmkj.auction.data.http;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by cunguoyao on 2017/9/20.
 */

public class GoodsCate implements Serializable {

    public int cat_id;
    public String cat_name;
    public int type;
    public String type_name;
    public int pid;
    public int p_order;
    public String cat_path;
    public boolean is_leaf;

    public static GoodsCate parseFromJson(JSONObject json){
        GoodsCate hotTopic = new GoodsCate();
        if(json != null) {
            hotTopic.cat_id = json.optInt("cat_id", 0);
            hotTopic.cat_name = json.optString("cat_name", "");
            hotTopic.type = json.optInt("type", 0);
            hotTopic.type_name = json.optString("type_name", "");
            hotTopic.pid = json.optInt("pid", 0);
            hotTopic.p_order = json.optInt("p_order", 0);
            hotTopic.cat_path = json.optString("cat_path", "");
            hotTopic.is_leaf = json.optBoolean("is_leaf", false);
        }
        return hotTopic;
    }

    public static List<GoodsCate> parseFromJsonArray(JSONArray array){
        List<GoodsCate> list = new ArrayList<GoodsCate>();
        if(array != null && array.length() > 0){
            for(int i=0;i<array.length();i++){
                list.add(parseFromJson(array.optJSONObject(i)));
            }
        }
        return list;
    }

    @Override
    public String toString() {
        return "GoodsCate{" +
                "cat_id=" + cat_id +
                ", cat_name='" + cat_name + '\'' +
                '}';
    }
}
